﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EasyCode.Utility;
using BusinessHandler;
/// <summary>
/// Summary description for GlobalVariable
/// </summary>
public class GlobalVariable
{
    public GlobalVariable()
    {
        //
        // TODO: Add constructor logic here
        //

    }
    public static bool isAdmin
    {
        get
        {
            if (HttpContext.Current.Session["IsAdmin"] != null && Protector.Bool(HttpContext.Current.Session["IsAdmin"].ToString(), false))
            {
                return true;
            }
            return false;
        }
        set
        {
            HttpContext.Current.Session["IsAdmin"] = value;
        }
    }
    public static string CurrentUserName
    {
        get
        {
            if (HttpContext.Current.Session["UserName"] == null)
                HttpContext.Current.Response.Redirect("login.aspx");
            return HttpContext.Current.Session["UserName"].ToString();
        }
        set
        {
            HttpContext.Current.Session["UserName"] = value;
        }
    }
    public static int CurrentUserID
    {
        get
        {
            return Protector.Int(HttpContext.Current.Session["CurrentUserID"], -1);
        }
        set
        {
            HttpContext.Current.Session["CurrentUserID"] = value;
        }
    }
    public static List<UsersInModule> GetCurrentRoles
    {
        get
        {
            if (HttpContext.Current.Session["GetCurrentRole"] == null)
            {
                UserInModuleController userInModuleController = UserInModuleController.Instance;
                HttpContext.Current.Session["GetCurrentRole"] = userInModuleController.GetUserInModule(CurrentUserID);
            }
            return HttpContext.Current.Session["GetCurrentRole"] as List<UsersInModule>;
        }
    }
    public static List<Module> GetModuleList
    {
        get
        {
            if (HttpContext.Current.Session["module"] == null)
            {
                ModuleController moduleController = new ModuleController();
                HttpContext.Current.Session["module"] = moduleController.GetModuleList();
            }
            return HttpContext.Current.Session["module"] as List<Module>;
        }
    }
    public static string CurrentPage
    {
        get
        {
            if (HttpContext.Current.Session["currentpage"] == null)
            {
                return string.Empty;
            }
            return HttpContext.Current.Session["currentpage"].ToString();
        }
        set 
        {
            HttpContext.Current.Session["currentpage"] = value;
        }
    }
}